/**
 * Created by Administrator on 2017/3/21.
 */
import React, {Component} from 'react';
import {Form, Input, Radio, Select, Switch, DatePicker,InputNumber } from 'antd';
import {connect} from 'dva';
import moment from 'moment'
const FormItem = Form.Item;
const { TextArea } = Input;
const RadioGroup = Radio.Group;
const Option = Select.Option;
class AddPoliciesForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
    };
  }

  render() {
    const formItemLayoutWithLabel = {
      labelCol: {
        xs: {span: 24},
        sm: {span: 6},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 15},
      }
    };

    const {getFieldDecorator} = this.props.form;
    return (
      <div>
        <Form onSubmit={this.handleSubmit}>
          <Form.Item label="所属分站"
                     {...formItemLayoutWithLabel}
          >
            {getFieldDecorator('company_id', {
              initialValue: this.props.editRecord?this.props.editRecord.company_id:sessionStorage.getItem('company_id'),
              rules: [{required: true, message:'所属分站不能为空'}],
            })(
              <Select disabled={Boolean(sessionStorage.getItem('company_id'))||this.props.editRecord} placeholder="请选择">
                {
                  JSON.parse(sessionStorage.getItem('management_companies')).map((item,index)=>{
                    return <Option key={index} value={item.id}>
                      {item.name}
                    </Option>
                  })
                }
              </Select>,
            )}
          </Form.Item>
          <FormItem label="水表厂商"
                    {...formItemLayoutWithLabel}
          >
            {getFieldDecorator('vendor_id', {
              initialValue: '129535925205221377',
              rules: [{required: true, message:'所属分站不能为空'}],
            })(
              <Select>
                {
                  this.props.all_vendors.map((item, index) => {
                    return <Option key={index} value={item.id}>{item.name}</Option>;
                  })
                }
              </Select>,
            )}
          </FormItem>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               抄表日期
            </span>
            )}
          >
            {getFieldDecorator('date', {
              initialValue: moment(),
              rules: [{required: true, message:'所属分站不能为空'}],
            })(
              <DatePicker style={{width:'100%'}} allowClear={false} />
            )}
          </FormItem>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               抄读率(%)
            </span>
            )}
          >
            {getFieldDecorator('normal_rate', {
              initialValue: this.props.editRecord ? this.props.editRecord.normal_rate : '',
              rules: [{required: true, message:'所属分站不能为空'}],
            })(
              <InputNumber max={100} min={0} style={{width:'100%'}}/>
            )}
          </FormItem>
        </Form>
      </div>
    );
  }
}

const AddPoliciesFormWrap = Form.create()(AddPoliciesForm);
export default connect()(AddPoliciesFormWrap);


